package com.example.demo.config;

import com.example.demo.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> pathPatternsList = new ArrayList<>();

        pathPatternsList.add("/admin/blog/pushBlog");                   // 发布文章
        pathPatternsList.add("/admin/blog/deleteBlogById");             // 删除文章
        pathPatternsList.add("/admin/blog/updateBlogById");             // 修改文章
        pathPatternsList.add("/admin/blog/deleteMessageForBlogById");   // 删除文章评论

        pathPatternsList.add("/admin/message/deleteMessageById");       // 删除留言板

        pathPatternsList.add("/admin/mood/pushMood");                   // 发布心情
        pathPatternsList.add("/admin/mood/deleteMoodById");             // 删除心情

        pathPatternsList.add("/admin/tag/saveTag");                     // 添加标签
        pathPatternsList.add("/admin/tag/deleteTagById");               // 删除标签

//        pathPatternsList.add("/admin/user/login");                      // 用户登录
//        pathPatternsList.add("/admin/user/logout");                     // 退出登录

        pathPatternsList.add("/fileUpload");                            // 文件上传

        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns(pathPatternsList);
    }
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }
}
